package com.pengweiwei.androidzygote.main;

import android.content.Context;
import android.text.TextUtils;

import com.putong35.common.utils.io.SharePreferenceUtil;


/**
 * SharePreference Dao
 *
 * @Author: PV
 * @E-mail: pengveivei@sina.cn
 * @CreateDate: 2016/7/7 16:49
 * @Version: 1.0.0
 */
public class SpDao {


    private static final String SP_FILENAME_COMMON = "sp_common";
    //第一次启动app
    private static final String KEY_FIRST_TIME_START_APP = "key_first_start_app";
    // 浏览过引导页
    private static final String KEY_SCAN_GUIDE = "key_scan_guide";

    // 营销推广 -》 搜索历史
    private static final String KEY_PROMOTION_SEARCH_HISTORY = "key_promotion_search_history";

    // 当前账户类
    private static final String KEY_ACCOUNT = "key_account";

    // 当前账户类
    private static final String KEY_LAST_LOGIN_NAME = "key_last_login_name";

    public static boolean isFirstTimeStartApp(Context context) {
        return SharePreferenceUtil.getBoolean(context, SP_FILENAME_COMMON, KEY_FIRST_TIME_START_APP, true);
    }

    public static void setKeyFirstTimeStartApp(Context context, boolean isFirstTime) {
        SharePreferenceUtil.saveBoolean(context, SP_FILENAME_COMMON, KEY_FIRST_TIME_START_APP, isFirstTime);
    }

    public static boolean isScanGuide(Context context) {
        return SharePreferenceUtil.getBoolean(context, SP_FILENAME_COMMON, KEY_SCAN_GUIDE, false);
    }

    public static void setScanGuide(Context context, boolean scanGuide) {
        SharePreferenceUtil.saveBoolean(context, SP_FILENAME_COMMON, KEY_SCAN_GUIDE, scanGuide);
    }


    public static void setKeyPromotionSearchHistoryStr(Context context, String str) {
        SharePreferenceUtil.saveString(context, SP_FILENAME_COMMON, KEY_PROMOTION_SEARCH_HISTORY, str);
    }

    public static void appendKeyPromotionSearchHistoryStr(Context context, String str) {
        String historyStr = getKeyPromotionSearchHistoryStr(context);
        if (TextUtils.isEmpty(historyStr)) {
            // + "xxxx"
            historyStr = str;
        } else {
            // + "|xxxx"
            historyStr += "|" + str;
        }
        setKeyPromotionSearchHistoryStr(context, historyStr);
    }

    public static String getKeyPromotionSearchHistoryStr(Context context) {
        return SharePreferenceUtil.getString(context, SP_FILENAME_COMMON, KEY_PROMOTION_SEARCH_HISTORY);
    }


    // 消息推送设置
    private static final String KEY_MSG_SWITCH_NEW_MSG = "key_msg_switch_new_msg";
    private static final String KEY_MSG_SWITCH_NOTIFY_SHOW_MSG_DETAIL = "key_msg_switch_notify_show_msg_detail";
    private static final String KEY_MSG_SWITCH_SYS_MSG_DISTURB = "key_msg_switch_sys_msg_disturb";
    private static final String KEY_MSG_SWITCH_SOUND = "key_msg_switch_sound";
    private static final String KEY_MSG_SWITCH_VIBRATE = "key_msg_switch_vibrate";

    public static boolean isVibrateSwitchEnable(Context context) {
        return SharePreferenceUtil.getBoolean(context, SP_FILENAME_COMMON, KEY_MSG_SWITCH_VIBRATE);
    }

    public static void setVibrateSwitch(Context context, boolean enable) {
        SharePreferenceUtil.saveBoolean(context, SP_FILENAME_COMMON, KEY_MSG_SWITCH_VIBRATE, enable);
    }

    public static boolean isSoundSwitchEnable(Context context) {
        return SharePreferenceUtil.getBoolean(context, SP_FILENAME_COMMON, KEY_MSG_SWITCH_SOUND);
    }

    public static void setSoundSwitch(Context context, boolean enable) {
        SharePreferenceUtil.saveBoolean(context, SP_FILENAME_COMMON, KEY_MSG_SWITCH_SOUND, enable);
    }

    public static boolean isNewMessageSwitchEnable(Context context) {
        return SharePreferenceUtil.getBoolean(context, SP_FILENAME_COMMON, KEY_MSG_SWITCH_NEW_MSG);
    }

    public static void setNewMessageSwitch(Context context, boolean enable) {
        SharePreferenceUtil.saveBoolean(context, SP_FILENAME_COMMON, KEY_MSG_SWITCH_NEW_MSG, enable);
    }

    public static boolean isShowMessageDetailNotifySwitchEnable(Context context) {
        return SharePreferenceUtil.getBoolean(context, SP_FILENAME_COMMON, KEY_MSG_SWITCH_NOTIFY_SHOW_MSG_DETAIL);
    }

    public static void setShowMessageDetailNotifySwitch(Context context, boolean enable) {
        SharePreferenceUtil.saveBoolean(context, SP_FILENAME_COMMON, KEY_MSG_SWITCH_NOTIFY_SHOW_MSG_DETAIL, enable);
    }

    public static boolean isSystemMessageDisturbSwitchEnable(Context context) {
        return SharePreferenceUtil.getBoolean(context, SP_FILENAME_COMMON, KEY_MSG_SWITCH_SYS_MSG_DISTURB);
    }

    public static void setSystemMessageDisturbSwitch(Context context, boolean enable) {
        SharePreferenceUtil.saveBoolean(context, SP_FILENAME_COMMON, KEY_MSG_SWITCH_SYS_MSG_DISTURB, enable);
    }



}
